<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>表单提交示例 - 基本表单提交</title>
</head>
<body>

<form action="/login" method="post" onsubmit="return beforeSubmit()">
    <label style="color: red" th:text="${msg}"></label><br/>
    用户：<input id="username" type="text" name="username" />
    密码：<input id="password" type="password" name="password" />
    <input type="submit" value="提交" />
</form>

<script type="text/javascript">
    function beforeSubmit() {
        var username = document.getElementById('username').value;
        var password = document.getElementById('password').value;
        if (username.length < 6 || password.length < 6) {
            alert('格式不正确！');
            return false;
        } else {
            return true;
        }
    }
</script>
</body>
</html>